#include <iostream>
#include <unistd.h>
using namespace std;

/*
    模板类
        只要类中使用到了模板，这个类就是来模板类
        定义：
            template <typename T>
            class 类名
            { };
        使用模板类：
            类名<类型> 对象名;
*/

struct student
{
    char name[20];
    int age;
};

template <typename T>
class Aipoint
{
public:
    Aipoint(int n)
    {
        p = new T[n];
        this->n = n;
        cout << "构造函数" << endl;
    }
    ~Aipoint()
    {
        delete[] p;
        cout << "析构函数" << endl;
    }
    void setValue(int i, T value)
    {
        if (i >= n)
        {
            cout << "数组越界" << endl;
            return;
        }
        
        p[i] = value;
    }
    void show();

private:
    T *p;
    int n;
};

template <typename T>
void Aipoint<T>::show()
{
    for (int i = 0; i < this->n; i++)
    {
        cout << p[i] << endl;
    }
}
template <>
void Aipoint<struct student>::show()
{
    for (int i = 0; i < this->n; i++)
    {
        cout << p[i].name << " " << p[i].age << endl;
    }
}
int main()
{
    Aipoint<int> a(10);
    for (int i = 0; i < 10; i++)
    {
        a.setValue(i, 11 + i);
    }
    cout << "----------------" << endl;
    a.show();
    
    Aipoint<student> b(1);
    b.setValue(0, {"张三", 18});

    cout << "----------------" << endl;
    b.show();
    return 0;
}